package com.five.matebook.activity.config;

import android.security.identity.EphemeralPublicKeyNotFoundException;

import com.five.matebook.activity.matebook.MateBookManager;
import com.five.matebook.activity.matebook.Matebook;
import com.five.matebook.utils.DateUtils;

import java.util.ArrayList;
import java.util.List;

public class ConfigDataBean {
    private long lastSyncTime = 0;
    private boolean isAdmin = false;

    private static final long ONE_DAY_MS = 24 * 3600 * 1000;

    private MateBookManager mateBookManagerNormal = new MateBookManager();
    private MateBookManager mateBookManagerAdmin = new MateBookManager();
    public ConfigDataBean() {
    }

    public void setMateBookManagerNormal(MateBookManager mateBookManagerNormal) {
        this.mateBookManagerNormal = mateBookManagerNormal;
    }

    public void setMateBookManagerAdmin(MateBookManager mateBookManagerAdmin) {
        this.mateBookManagerAdmin = mateBookManagerAdmin;
    }

    public MateBookManager getMateBookManagerAdmin() {
        return mateBookManagerAdmin;
    }

    public MateBookManager getMateBookManagerNormal() {
        return mateBookManagerNormal;
    }

    public MateBookManager getMateBookManager() {
        return isAdmin() ? mateBookManagerAdmin : mateBookManagerNormal;
    }

    public synchronized void setHasUpdate(boolean update) {
        if (update) {
            getMateBookManager().getNowChoosed().setHasUpdate(update);
        } else {
            getMateBookManager().setHasUpdate(update);
        }
    }

    public boolean needPush2Server() {
        long now = DateUtils.getNowTimeLong();
        return getMateBookManager().hasUpdate() && (now - lastSyncTime) > ONE_DAY_MS;
    }

    public void setLastSyncTime(long lastSyncTime) {
        this.lastSyncTime = lastSyncTime;
    }

    public long getLastSyncTime() {
        return lastSyncTime;
    }

    public void setAdmin(boolean admin) {
        isAdmin = admin;
    }

    public boolean isAdmin() {
        return isAdmin;
    }

    public void toggleAdmin() {
        this.isAdmin = !this.isAdmin;
    }
}
